package com.bristua.mall.order.biz;

import com.bristua.mall.common.exception.BizException;
import com.bristua.mall.common.utils.DateUtil;
import com.bristua.mall.order.dao.TOrderMapper;
import com.bristua.mall.order.enums.OrderCode;
import com.bristua.mall.order.model.TOrder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * Created by Administrator on 2019/3/24.
 */
@Service
@Transactional
public class CancelOrderBiz {

    @Resource
    private TOrderMapper tOrderMapper;

    public void cancelOrder(String orderId){
        TOrder tOrder = tOrderMapper.selectByPrimaryKey(orderId);
        if(tOrder==null){
            throw new BizException(OrderCode.ORDER_NOT_FIND.getCode(),OrderCode.ORDER_NOT_FIND.getMsg());
        }
        if("2".equals(tOrder.getPayStaus())){
            throw new BizException(OrderCode.ORDER_HAS_PAY.getCode(),OrderCode.ORDER_HAS_PAY.getMsg());
        }else{
            tOrder.setOrderStatus("2");
            tOrder.setCancelTime(DateUtil.getDateTime3());
            tOrderMapper.updateByPrimaryKeySelective(tOrder);
        }

    }
}
